from flask import Flask, render_template, request, make_response, jsonify
from werkzeug.utils import secure_filename
import os
from flask_cors import *

app = Flask(__name__)
CORS(app, supports_credentials=True)

@app.route('/answer', methods=['POST'])
def getAnswer():
    qs = request.form['question']
    dict = {'a':'yes', 'b':'no'}
    print(qs)
    return dict[qs]
    pass


@app.route('/upload', methods=['POST'])
def getImage():
    f = request.files['file']
    base_path = os.path.dirname(__file__)
    upload_path = os.path.join(base_path, 'static/image', secure_filename(f.filename))
    f.save(upload_path)

    image_data = open(upload_path, "rb").read()
    response = make_response(image_data)
    response.headers['Content-Type'] = 'image/*'
    return response
    pass

@app.route('/')
def hello_world():
    answer = 'he'
    return render_template('index.html')


if __name__ == '__main__':
    app.run(debug=True)
